import json
import unittest
from parameterized import parameterized
import requests

# 构造测试数据
def build_data():
    test_data = []
    file = '../DataXml/login.json'
    with open(file, encoding='utf-8') as f:
        json_data = json.load(f)
        # print(json_data)
        for case_data in json_data:
            username = case_data.get("username")
            password = case_data.get("password")
            status_code = case_data.get("status_code")
            message = case_data.get("message")
            code = case_data.get("code")

            test_data.append((username, password, status_code, message, code))
    print("test_data=".format(username, password, status_code, message, code))
    return test_data


class loginTest2(unittest.TestCase):
    def setUp(self) -> None:
        self.url = "http://ihrm-test.itheima.net/api/sys/login"
        print("start")
    def tearDown(self) -> None:
        print("end")

    @parameterized.expand(build_data())
    def test001(self,username,password,status_code,message,code):
        json = {"mobile":username,"password":password}
        respones = requests.post(self.url,json=json)
        print(respones.json())
        print(respones.json().get('success'))
        print(respones.json().get("message"))
        print(respones.headers.get("Content-Type"))
        print(respones.status_code)
        self.assertEqual(status_code,respones.status_code)
        self.assertEqual(message,respones.json().get('message'))
        self.assertEqual(code,respones.json().get('code'))






